package com.zhongyu.item.provider.apiimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhongyu.comm.api.ItemApi;

import com.zhongyu.comm.pojo.Item;
import com.zhongyu.item.provider.mapper.ItemMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@RestController
public class ItemApiImpl implements ItemApi {

    @Resource
    private ItemMapper itemMapper;

    @Override
    public List<Item> findTopN(Integer ItemTypeId, Integer top) {
        QueryWrapper<Item> queryWrapper= Wrappers.query();
        queryWrapper
                .eq("item_type1_id",ItemTypeId)
                .orderByDesc("comment_count","avg_score","start_time")
                 .last("limit "+top);
         List<Item> list= itemMapper.selectList(queryWrapper);
        //list.stream().map(item -> transform(item));
      return list;
    }
    @Override
    public List<Item> findrejiemu(Integer ItemTypeId) {
        QueryWrapper<Item> queryWrapper=Wrappers.query();
        queryWrapper.eq("item_type1_id", ItemTypeId);
        return itemMapper.selectList(queryWrapper);
    }

    @Override
    public Item findById(Integer id) {

        return itemMapper.selectById(id);
    }

    @Override
    public List<Item> findAll() {
        return itemMapper.selectList(null);
    }

    @Override
    public List<Item> findBySyncTime(LocalDateTime syncTime) {
        QueryWrapper<Item> queryWrapper=Wrappers.query();
        queryWrapper.ge("created_Time", syncTime);
        queryWrapper.or();
        queryWrapper.ge("updated_Time",syncTime);
        return itemMapper.selectList(queryWrapper);
    }
}
